package logic

import (
	"context"
	"github.com/zeromicro/go-zero/core/logx"
	"img_analyse/user/api/internal/svc"
	"img_analyse/user/api/internal/types"
	"img_analyse/user/rpc/types/user"
)

type ResetPasswordLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewResetPasswordLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ResetPasswordLogic {
	return &ResetPasswordLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ResetPasswordLogic) ResetPassword(req *types.ResetPasswordRequest) (resp *types.ResetPasswordResponse, err error) {
	// todo: add your logic here and delete this line
	response, err := l.svcCtx.UserRpc.ResetPassword(l.ctx, &user.ResetPasswordRequest{
		Username:     req.UserName,
		Newpassword1: req.NewPassword1,
		Newpassword2: req.NewPassword2,
	})
	if err != nil {
		l.Logger.Error("重置密码失败", logx.Field("err", err))
		return nil, err
	}
	return &types.ResetPasswordResponse{
		UserId:   int64(response.UserId),
		UserName: response.Username,
	}, nil
}
